#include<bits/stdc++.h>
using namespace std ;
int n , a[20] ;
void solve(){
    cin >> n ;
    int mx = 0 ;
    for(int i = 1 ; i <= n ; i++) cin >> a[i] ;
    for(long long i = 0 ; i <= (1 << n) - 1 ; i++){
        int lb = -1 , lr = -1 , s = 0 ;
        for(int j = 1 ; j <= n ; j++){
            if((i & (1 << (j - 1))) != 0){
                //cout << i << ' ' << j << ' ' << lb << "\n" ;
                if(lb == -1) lb = j ;
                else{
                    if(a[lb] == a[j]) s += a[j] ;
                    lb = j ;
                }
            }
            else{
                if(lr == -1) lr = j ;
                else{
                    if(a[lr] == a[j]) s += a[j] ;
                    lr = j ;
                }
            }
        }
        mx = max(mx , s) ;
    }
    cout << mx << "\n" ;
}
int main(){
    //cin.tie(0) ;cout.tie(0) ;
    //ios::sync_with_stdio(0) ;
    freopen("color.in","r",stdin) ;
    freopen("color.out","w",stdout) ;
    int t ;
    cin >> t ;
    while(t--) solve() ;
    return 0 ;
}
